import java.util.Arrays;
import java.util.Comparator;

class Student {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
class AgeComparable implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}
class NameComparable implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);

    }
}
public class Test {
    public static void main(String[] args) {
        /*Student student1=new Student("zhangsan",10);
        Student student2=new Student("lisi",23);
        AgeComparable ageComparable=new AgeComparable();
        System.out.println(ageComparable.compare(student1, student2));
        NameComparable nameComparable=new NameComparable();
        System.out.println(nameComparable.compare(student1, student2));*/
        AgeComparable ageComparable=new AgeComparable();
        Student[] students=new Student[3];
        students[0]=new Student("zhangsan",10);
        students[1]=new Student("lisi",20);
        students[2]=new Student("wangwu",28);
        Arrays.sort(students,ageComparable);
        System.out.println(Arrays.toString(students));
        NameComparable nameComparable=new NameComparable();
        Arrays.sort(students,nameComparable);
        System.out.println(Arrays.toString(students));
    }
}
